/*
 * destroy_file_test.c
 * Created by mofei on 15/11/02
 */

#include <stdio.h>
#include <stdlib.h>
#include <time.h>

/* print short notice */
void notice(int i, char *s);

/* core function */
void wipe(FILE *f, char c);

/* get the size of a file */
long file_size(FILE *f);

int require(int c, char *s[]);

int main(int argc, char *argv[]) {
	int i, j;
	char ch;

	FILE *f;

	notice(1, argv[0]);

	if(argc < 2) {
		/* two few arguments */
		notice(2, argv[0]);
		exit(0);
	}

	if(!require(argc, argv)) {
		/* cancel */
		fprintf(stderr, "Cancel Operating.\n");
		exit(0);
	}

	/* randomize */
	srand(time(NULL));

	/* process each file */
	for(i = 1; i < argc; ++i) {
		/* fail to open file */
		if((f = fopen(argv[i], "r+b")) == NULL) {
			fprintf(stderr, "Error when open %s:\n", argv[i]);
			exit(0);
		}
		
		for(j = 0; j < 3; ++j) {
			wipe(f, 0x00);
			wipe(f, 0x01);
		}
		
		wipe(f, rand() % 256);

		if(rename(argv[i], "C")) {
			fprintf(stderr, "Error when rename %s\n", argv[i]);
			exit(0);
		}
		
		fclose(f);
	}

	printf("Done! Destroy %d files\n", argc - 1);

	retrun 0;
}






